

************************
** Study 2: Figure S2.15
************************



** 2017 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 pol_interest4 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2015_1 vote2015_2 vote2015_3 vote2015_4 vote2015_5 vote2015_6 vote2015_7 vote2015_8 vote2015_9 vote2015_10 refvote2016_1 refvote2016_2 refvote2016_3 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2017.dta", replace

* Time dummies
sum statadate if postattack == .
gen eventtime = statadate - 20973
tab eventtime postattack

forvalues i = 2/3 {
	gen pre_`i' = (eventtime == -`i')	
}
forvalues i = 1/5 {
	gen post_`i' = (eventtime == `i')	
}

* Regressions
foreach dv of varlist sec imm britid englid {
reg `dv' pre_* post_* $covars_binaries if eventtime >= -3 & eventtime != 0
estimates store `dv'
}

* Results table
gen day = _n - 4
foreach dv of varlist sec imm britid englid {
gen n_`dv' = .
gen coef_`dv' = .
gen se_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
estimates restore `dv'
replace n_`dv' = `e(N)'
forvalues i = 2/3 {
	replace coef_`dv' = _b[pre_`i'] if day == -`i'
	replace se_`dv' = _se[pre_`i'] if day == -`i'
}
forvalues i = 1/5 {
	replace coef_`dv' = _b[post_`i'] if day == `i'
	replace se_`dv' = _se[post_`i'] if day == `i'
}
replace ll_`dv' = coef_`dv' - 1.96*se_`dv'
replace ul_`dv' = coef_`dv' + 1.96*se_`dv'
replace d_`dv' = coef_`dv'/sd_`dv'
replace dlow_`dv' = coef_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv'
replace dup_`dv' = coef_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv'
replace coef_`dv' = 0 if day == -1
replace d_`dv' = 0 if day == -1
}
drop id - post_5 _est*
keep if day < 14
gen year = 2017
order year

save "SingleDays2017.dta", replace




** 2019 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2017_1 vote2017_2 vote2017_3 vote2017_4 vote2017_5 vote2017_6 vote2017_7 vote2017_8 vote2017_9 vote2017_10 vote2017_11 refvote2016_1 refvote2016_2 refvote2016_3 refvote2016_4 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2019.dta", replace

* Time dummies
sum statadate if postattack == .
gen eventtime = statadate - 21882
tab eventtime postattack

forvalues i = 2/3 {
	gen pre_`i' = (eventtime == -`i')	
}
forvalues i = 1/13 {
	gen post_`i' = (eventtime == `i')	
}

* Regressions
foreach dv of varlist sec imm britid englid {
reg `dv' pre_* post_* $covars_binaries if eventtime >= -3 & eventtime != 0
estimates store `dv'
}

* Results table
gen day = _n - 4
foreach dv of varlist sec imm britid englid {
gen n_`dv' = .
gen coef_`dv' = .
gen se_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
estimates restore `dv'
replace n_`dv' = `e(N)'
forvalues i = 2/3 {
	replace coef_`dv' = _b[pre_`i'] if day == -`i'
	replace se_`dv' = _se[pre_`i'] if day == -`i'
}
forvalues i = 1/13 {
	replace coef_`dv' = _b[post_`i'] if day == `i'
	replace se_`dv' = _se[post_`i'] if day == `i'
}
replace ll_`dv' = coef_`dv' - 1.96*se_`dv'
replace ul_`dv' = coef_`dv' + 1.96*se_`dv'
replace d_`dv' = coef_`dv'/sd_`dv'
replace dlow_`dv' = coef_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv'
replace dup_`dv' = coef_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv'
replace coef_`dv' = 0 if day == -1
replace d_`dv' = 0 if day == -1
}
drop id - post_13 _est*
keep if day < 14
gen year = 2019
order year

save "SingleDays2019.dta", replace





** Figure
*********



* 2017
use "SingleDays2017.dta", replace

sum n_sec in 1
local n = "`r(mean)'"
twoway ///
	(scatter d_sec day, mcolor(gs2) msymbol(o) msize(medsmall)) ///
	(rspike dlow_sec dup_sec day, lcolor(gs2)) ///
	, ///
	ytitle("Effect of terrorist attack (Cohen's {it:d})") yscale(noline) ///
	ylabel(-0.20(0.10)0.40, angle(horizontal) nogrid) ///
	xtitle("Days before/after terrorist attack", margin(small)) xscale(noline) ///
	title(Security ({it:N} = `n')) ///
	xlabel(-3(1)13, tlcolor(black)) ///
	legend(off) ///
	yline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(red) extend) ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(10) ysize(8) saving(sec17.gph, replace)
	
sum n_imm in 1
local n = "`r(mean)'"
twoway ///
	(scatter d_imm day, mcolor(gs2) msymbol(o) msize(medsmall)) ///
	(rspike dlow_imm dup_imm day, lcolor(gs2)) ///
	, ///
	ytitle("Effect of terrorist attack (Cohen's {it:d})") yscale(noline) ///
	ylabel(-0.20(0.10)0.40, angle(horizontal) nogrid) ///
	xtitle("Days before/after terrorist attack", margin(small)) xscale(noline) ///
	title(Immigration ({it:N} = `n')) ///
	xlabel(-3(1)13, tlcolor(black)) ///
	legend(off) ///
	yline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(red) extend) ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(10) ysize(8) saving(imm17.gph, replace)
	
sum n_britid in 1
local n = "`r(mean)'"
twoway ///
	(scatter d_britid day, mcolor(gs2) msymbol(o) msize(medsmall)) ///
	(rspike dlow_britid dup_britid day, lcolor(gs2)) ///
	, ///
	ytitle("Effect of terrorist attack (Cohen's {it:d})") yscale(noline) ///
	ylabel(-0.20(0.10)0.40, angle(horizontal) nogrid) ///
	xtitle("Days before/after terrorist attack", margin(small)) xscale(noline) ///
	title(British identity ({it:N} = `n')) ///
	xlabel(-3(1)13, tlcolor(black)) ///
	legend(off) ///
	yline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(red) extend) ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(10) ysize(8) saving(britid17.gph, replace)	
	
sum n_englid in 1
local n = "`r(mean)'"
twoway ///
	(scatter d_englid day, mcolor(gs2) msymbol(o) msize(medsmall)) ///
	(rspike dlow_englid dup_englid day, lcolor(gs2)) ///
	, ///
	ytitle("Effect of terrorist attack (Cohen's {it:d})") yscale(noline) ///
	ylabel(-0.20(0.10)0.40, angle(horizontal) nogrid) ///
	xtitle("Days before/after terrorist attack", margin(small)) xscale(noline) ///
	title(English identity ({it:N} = `n')) ///
	xlabel(-3(1)13, tlcolor(black)) ///
	legend(off) ///
	yline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(red) extend) ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(10) ysize(8) saving(englid17.gph, replace)	
	
	
graph combine sec17.gph imm17.gph britid17.gph englid17.gph, ///
		altshrink title(2017, size(medlarge)) iscale(*1.6) ///
		graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white)) ///
		scheme(s2mono) xsize(10) ysize(8) saving(daybyday17.gph, replace)
		
		
* 2019
use "SingleDays2019.dta", replace

sum n_sec in 1
local n = "`r(mean)'"
twoway ///
	(scatter d_sec day, mcolor(gs2) msymbol(o) msize(medsmall)) ///
	(rspike dlow_sec dup_sec day, lcolor(gs2)) ///
	, ///
	ytitle("Effect of terrorist attack (Cohen's {it:d})") yscale(noline) ///
	ylabel(-0.20(0.10)0.40, angle(horizontal) nogrid) ///
	xtitle("Days before/after terrorist attack", margin(small)) xscale(noline) ///
	title(Security ({it:N} = `n')) ///
	xlabel(-3(1)13, tlcolor(black)) ///
	legend(off) ///
	yline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(red) extend) ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(10) ysize(8) saving(sec19.gph, replace)
	
sum n_imm in 1
local n = "`r(mean)'"
twoway ///
	(scatter d_imm day, mcolor(gs2) msymbol(o) msize(medsmall)) ///
	(rspike dlow_imm dup_imm day, lcolor(gs2)) ///
	, ///
	ytitle("Effect of terrorist attack (Cohen's {it:d})") yscale(noline) ///
	ylabel(-0.20(0.10)0.40, angle(horizontal) nogrid) ///
	xtitle("Days before/after terrorist attack", margin(small)) xscale(noline) ///
	title(Immigration ({it:N} = `n')) ///
	xlabel(-3(1)13, tlcolor(black)) ///
	legend(off) ///
	yline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(red) extend) ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(10) ysize(8) saving(imm19.gph, replace)
	
sum n_britid in 1
local n = "`r(mean)'"
twoway ///
	(scatter d_britid day, mcolor(gs2) msymbol(o) msize(medsmall)) ///
	(rspike dlow_britid dup_britid day, lcolor(gs2)) ///
	, ///
	ytitle("Effect of terrorist attack (Cohen's {it:d})") yscale(noline) ///
	ylabel(-0.20(0.10)0.40, angle(horizontal) nogrid) ///
	xtitle("Days before/after terrorist attack", margin(small)) xscale(noline) ///
	title(British identity ({it:N} = `n')) ///
	xlabel(-3(1)13, tlcolor(black)) ///
	legend(off) ///
	yline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(red) extend) ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(10) ysize(8) saving(britid19.gph, replace)	
	
sum n_englid in 1
local n = "`r(mean)'"
twoway ///
	(scatter d_englid day, mcolor(gs2) msymbol(o) msize(medsmall)) ///
	(rspike dlow_englid dup_englid day, lcolor(gs2)) ///
	, ///
	ytitle("Effect of terrorist attack (Cohen's {it:d})") yscale(noline) ///
	ylabel(-0.20(0.10)0.40, angle(horizontal) nogrid) ///
	xtitle("Days before/after terrorist attack", margin(small)) xscale(noline) ///
	title(English identity ({it:N} = `n')) ///
	xlabel(-3(1)13, tlcolor(black)) ///
	legend(off) ///
	yline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(red) extend) ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(10) ysize(8) saving(englid19.gph, replace)	
	
	
graph combine sec19.gph imm19.gph britid19.gph englid19.gph, ///
		altshrink title(2019, size(medlarge)) iscale(*1.6) ///
		graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white)) ///
		scheme(s2mono) xsize(10) ysize(8) saving(daybyday19.gph, replace)

		
* Combine 2017 & 2019	
graph combine daybyday17.gph daybyday19.gph, ///
		rows(2) altshrink iscale(*1.6) ///
		graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white)) ///
		scheme(s2mono) xsize(10) ysize(16) 	





** Tidy Up
**********

erase "SingleDays2017.dta"
erase "SingleDays2019.dta"
erase sec17.gph
erase imm17.gph
erase britid17.gph
erase englid17.gph
erase sec19.gph
erase imm19.gph
erase britid19.gph
erase englid19.gph
erase daybyday17.gph 
erase daybyday19.gph
